package interfaz2;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

/**
 * Class that handles Exceptions. Any time we want to control an Exception
 * inside Dust we should create an instance of this class. What it will do is
 * pop up a dialog with the message of the Exception and print in the console
 * the stack trace.
 * 
 * @author ole
 */
public class ExceptionBox {
	private MessageBox box;
	private Exception exception;
	
	/**
	 * Class constructor.
	 * 
	 * @param e
	 * 		The Exception that had been thrown.
	 * @param parent
	 * 		The shell where the dialog must pops up.
	 */
	public ExceptionBox(Exception e, Shell parent) {
		exception = e;
		box = new MessageBox(parent, SWT.ICON_ERROR);
		box.setText("WTF!");
		if (e.getMessage() != null)
			box.setMessage(e.getMessage());
		else
			box.setMessage("Bogus error.\nNot even a message with it.");
	}
	
	/**
	 * Method that pops up the dialog and print the stack trace.
	 */
	public void popError() {
		exception.printStackTrace();
		box.open();
	}
}
